#include "Customer.h"

using namespace ecocity;

static const QString string_amigos = "Amigos";
static const QString string_coope = "Cooperativa";
static const QString string_tienda = "Tienda";
static const QString string_consumidor_final = "Consumidor final";


//---------------------------------------------------------------

Customer::Customer( int id,
                    const QString& name,
                    const QString& address,
                    const QString& phone,
                    const QString& nif,
                    TYPE type )
    : m_id( id ),
      m_name( name ),
      m_address( address ),
      m_phone( phone ),
      m_nif( nif ),
      m_type( type )
{
}

//---------------------------------------------------------------

int
Customer::id( ) const
{
    return m_id;
}

//---------------------------------------------------------------

const QString&
Customer::name( ) const
{
    return m_name;
}

//---------------------------------------------------------------

const QString&
Customer::address( ) const
{
    return m_address;
}

//---------------------------------------------------------------

const QString&
Customer::phone( ) const
{
    return m_phone;
}

//---------------------------------------------------------------

const QString&
Customer::nif( ) const
{
    return m_nif;
}

//---------------------------------------------------------------

Customer::TYPE
Customer::type( ) const
{
    return m_type;
}

//---------------------------------------------------------------

const QString
Customer::to_string( TYPE type )
{
    switch( type )
    {
    case Customer::FRIENDS: return string_amigos;
    case Customer::COOPERATIVA: return string_coope;
    case Customer::TIENDA: return string_tienda;
    case Customer::CONSUMIDOR_FINAL: return string_consumidor_final;

    default: return QString( );
    }
}

//---------------------------------------------------------------

Customer::TYPE
Customer::to_customer_type( const QString& type )
{
    QString lower_case_type = type.toLower( );

    if( lower_case_type == string_amigos.toLower( ) )
    {
        return Customer::FRIENDS;
    }
    else if( lower_case_type == string_coope.toLower( ) )
    {
        return Customer::COOPERATIVA;
    }
    else if( lower_case_type == string_tienda.toLower( ) )
    {
        return Customer::TIENDA;
    }
    else if( lower_case_type == string_consumidor_final.toLower( ) )
    {
        return Customer::CONSUMIDOR_FINAL;
    }
    else
    {
        return Customer::UKNOWN;
    }
}

